package com.java.leetcode;

/**
 * @Author ynb
 * 27. 移除元素
 * @Date 2021/5/28 16:47
 * @Version 1.0
 */
public class LeetCode027 {
    public int removeElement(int[] nums, int val) {
        if (nums.length==0||nums==null){
            return 0;
        }
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[index++]=nums[i];
            }
        }
        for (int n:nums){
            System.out.println(n);
        }
        return index;
    }

    public static void main(String[] args) {
        LeetCode027 l027 = new LeetCode027();
        int[] nums = {3,2,2,3};
        int val = 2;
        int i = l027.removeElement(nums, val);
        System.out.println("--------------------------");
        for (int j=0;j<i;j++){
            System.out.print(nums[j]+" ");
        }
        System.out.println();
        System.out.println(i);
    }
}
